﻿@*学生用户列表页面*@
@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>学生用户管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 3)
    <div class="container mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="javascript:void(0)"><span class="glyphicon glyphicon-list"></span> 学生用户列表</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/UserInfo/AddStudent?@para"><span class="glyphicon glyphicon-user"></span> 新增学生用户</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/UserInfo/StudentGrpList?@para"><span class="glyphicon glyphicon-list"></span> 学生用户组列表</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/UserInfo/AddStudentGrp?@para"><span class="glyphicon glyphicon-plus"></span> 新增学生用户组</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <ol class="breadcrumb">
                            <li>学生用户管理</li>
                            <li class="active">学生用户列表</li>
                        </ol>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <div class="col-xs-3">
                                        <input type="text" class="form-control" id="Jaccount" placeholder="请输入学号">
                                    </div>
                                    <div class="col-xs-3">
                                        <input type="text" class="form-control" id="JgrpName" placeholder="请输入组名">
                                    </div>
                                    <div class="col-xs-4">
                                        <button type="button" class="btn btn-success" id="JstdSearch"><span class="glyphicon glyphicon-search"></span> 搜索 </button>
                                        <!--<button type="button" class="btn btn-success"><span class="glyphicon glyphicon-download-alt"></span> 导出 </button>-->
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="row">
                            <table class="table table-bordered tb1">
                                <thead>
                                    <tr>
                                        <th width="20%">学号</th>
                                        <th width="15%">姓名</th>
                                        <th width="15%">发帖数</th>
                                        <th width="15%">回帖数</th>
                                        <th width="25%">操作</th>
                                    </tr>
                                </thead>
                                <tbody id="JgrpTbody">

                                </tbody>
                            </table>
                        </div>
                        <div class="row clearfix well">
                            <div id="PagInfo" class="pull-left sum"></div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 更改密码的弹框 -->
    <div class="modal fade" id="changePwModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel">修改密码</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
            <label for="JcGrpName">输入密码：</label>
            <input type="text" class="form-control" id="Jcpw" placeholder="请输入新密码">
            </div>
            <div class="form-group">
            <label for="JcRemark">确认密码：</label>
            <input type="text" class="form-control" id="Jcpw2" placeholder="请再次输入密码">
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" id="JcSubmit" class="btn btn-info">确认修改</button>
          </div>
        </div>
      </div>
    </div>
    <!-- 更改信息的弹框 -->
    <div class="modal fade" id="changeGrpModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel2">编辑</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
            <label for="JcRemark">姓名：</label>
            <input type="text" class="form-control" id="JcRealName" placeholder="">
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" id="JcSubmit2" class="btn btn-info">确认修改</button>
          </div>
        </div>
      </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script>
        var account = $("#Jaccount"),
            grpName = $("#JgrpName"),
            grpSel = $("#JgrpSel"),
            stdSearch = $("#JstdSearch"),
            _account = account.val(),
            _grp = grpName.val(),
            page = 1,
            grpTbody = $("#JgrpTbody");
       
        stdSearch.bind("click", function () {
            _account = account.val(),
             _grp = grpName.val();
            getList(page, _account, _grp);
        })
        function getList(pageNo, account, grpname) {
            page = pageNo;
            _account = account;
            _grp = grpname;
            $.easyPost("/UserInfo/GetUserInfoList", {
                "PageNO": pageNo,
                "PageSize": 10,
                "Account": account,
                "GrpName": grpname
            }, function (data) {
                if (!data.result) {
                    showTips.open(data.message);
                    return;
                }
                if (data.rows.length > 0) {
                    var _row = data.rows,
                        _rowL = _row.length,
                        _html = '';
                    var options = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: pageNo,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getList(page, _account, _grp);
                        }
                    }
                    initialPaginator(options, "PageTool", "PagInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var _grpInfo = _row[i];
                        _html += '<tr data-grpid=\"' + _grpInfo.Entity.Id.trim() + '\">' +
                                     '<td class=\"account\">' + _grpInfo.Entity.Account + '</td>' +
                                     '<td class=\"realName\">' + _grpInfo.Entity.RealName + '</td>' +
                                     '<td>' + _grpInfo.DiscussCount + '</td>' +
                                     '<td>' + _grpInfo.CommentCount + '</td>' +
                                     '<td>' +
                                         '<a class=\"operate aChangePW\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-lock\"><\/span> 重置密码<\/a>' +
                                         '<a class=\"operate aEdit\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-pencil\"><\/span> 编辑<\/a>' +
                                     '</td>' +
                                 '</tr>'
                    }
                    grpTbody.html(_html)
                } else {
                    var _html = '<tr><td colspan="5" align="center">暂无内容</td></tr>'
                    grpTbody.html(_html)
                }
            }, "json");
        }
        getList(page, _account, _grp);
        var changeGrpModal = $("#changeGrpModal"),
            JcRealName = $("#JcRealName"),
            changePwModal = $("#changePwModal"),
            Jcpw = $("#Jcpw"),
            Jcpw2 = $("#Jcpw2");
        grpTbody.bind("click", function (e) {
            var _self = $(e.target);
            if (_self.hasClass("aEdit") || _self.parent().hasClass("aEdit")) {
                var _edit = _self.hasClass("aEdit") ? _self : _self.parent(),
                    _tr = _edit.parent().parent(),
                    _ant = $(".account", _tr).html(),
                    _realName = $(".realName", _tr).html();
                JcRealName.attr("data-account", _ant);
                JcRealName.val(_realName);
                changeGrpModal.modal("show");
                setTimeout(function () {
                    JcRealName.focus().select();
                }, 500)
            } else if (_self.hasClass("aChangePW") || _self.parent().hasClass("aChangePW")) {
                var _change = _self.hasClass("aChangePW") ? _self : _self.parent(),
                   _tr = _change.parent().parent(),
                   _ant = $(".account", _tr).html();
                changePwModal.attr("data-ant", _ant);
                changePwModal.modal("show");
                setTimeout(function () {
                    Jcpw.focus().select();
                }, 500)
            }
        })
        $("#JcSubmit2").bind("click", function () {
            var _ant = JcRealName.attr("data-account"),
                _realName = JcRealName.val();
            $.easyPost("/UserInfo/EditStudent", {
                "Account": _ant,
                "RealName": _realName                 
            }, function (data) {
                if (data.result) {
                    showTips.open("修改成功！");
                    changeGrpModal.modal("hide")
                    getList(page, _account, _grp);
                    return;
                } else {
                    showTips.open(data.message)
                }
            }, "json")

        })
        $("#JcSubmit").bind("click", function () {
            var _pw = Jcpw.val(),
                _pw2 = Jcpw2.val(),
                _ant = changePwModal.attr("data-ant");
            $.easyPost("/UserInfo/ResetStudentPassword", {
                "Account": _ant,
                "Password": _pw,
                "Password2": _pw2
            }, function (data) {
                if (data.result) {
                    showTips.open("修改成功！");
                    changePwModal.modal("hide")
                    getList(page, _account, _grp);
                    return;
                } else {
                    showTips.open(data.message)
                }
            }, "json")
        })
    </script>
</body>
</html>
